home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************************
- Smaller Installer © 1996 Bill Goodman, All Rights Reserved
- *******************************************************************************
-
- SaveAs Hook Example
-
- This installer hook procedure allows the user to select the destination folder
- for an installed item (either a file or folder). It also allows the user to
- change the name of the installed item.
-
- Limitations: This hook will not work with installers that must "remove" items.
- It also will not allow a user to install a folder over an existing folder.
-
- To build this hook procedure, compile this code and create a code resource
- (Type:SICR, ID:501, non-preloaded, nonpurgeable, unlocked, unprotected,
- non-sysheap). Add this resource to the "SetNameHook.rsrc" file. Copy all the
- resources in "SetNameHook.rsrc" to your installer's resource file.
-
- Set the strings in the STR#:500 resource to the following values:
- 1 - Name of item to relocate (must be unique in archive)
- 2 - Prompt string for install dialog
-
- ******************************************************************************/
-
- // This file is compatible with version 2.1 of the universal headers
- #include <LowMem.h>
- #include <StandardFile.h>
- #include <TextUtils.h>
-
- #ifdef __MWERKS__
- #include <A4Stuff.h>
- #endif
-
- #ifdef THINK_C
- #include <SetUpA4.h>
- #endif
-
- #include "SIHookProc.h"
-
-
- /******************************************************************************
- Module Internal Function Prototypes
- ******************************************************************************/
- void BeforeItemFunction(void);
- void BeginOperationFunction(void);
-
-
- /******************************************************************************
- Constant Definitions
- ******************************************************************************/
- // Dialog Definitions
- #define selectDlg 500 // Select dialog
-
- // Alert Definitions
- #define changeVolAlrt 510 // "If you wish to use a different volume, please use the DRIVE button to select the volume and try again."
-
- // Indexed String Definitions
- #define genIStrID 500 // Indexed string resource ID
- enum
- {
- itemNameIStr = 1, // Name of item to relocate
- installPromptIStr // Prompt string for install dialog
- };
-
-
- /******************************************************************************
- Module Variable Definitions
- ******************************************************************************/
- SIHookParmBlk *gParms; // Global pointer to parameter block
- unsigned char gEmptyStr[] = "\p"; // Global empty string
- Str63 gItemName; // Name of item to relocate
- long gInstallDirID; // Directory ID of install item
- Str63 gInstallName; // Name of install item
-
-
- /*****************************************************************************/
- pascal void main(
- SIHookParmBlk *parmBlk // Pointer to parameter block
- )
- /******************************************************************************
- This is the main entry point for the installer hook procedure.
- ******************************************************************************/
- {
- #ifdef __MWERKS__
- long holdA4;
- #endif
-
- // Set up access to global variables
- #ifdef THINK_C
- RememberA0();
- SetUpA4();
- #endif
-
- #ifdef __MWERKS__
- holdA4 = SetCurrentA4();
- #endif
-
- gParms = parmBlk;
-
- switch (gParms->function)
- {
- case siHookBeginOperation:
- BeginOperationFunction();
- break;
-
- case siHookBeforeItem:
- BeforeItemFunction();
- break;
- }
-
- // Restore original A4 value
- #ifdef THINK_C
- RestoreA4();
- #endif
-
- #ifdef __MWERKS__
- SetA4(holdA4);
- #endif
- }
-
-
- /*****************************************************************************/
- void BeginOperationFunction(void)
- /******************************************************************************
- Input parameters:
- "targetVRefNum" Volume reference number of target volume
- "groupAPFlags" Groups currently selected
- "groupQUSel"
- "groupVZSel"
- "group32Flags"
- "group64Flags"
- "group96Flags"
- "groupEnvironFlags"
- "passwordPtr" Pointer to password string
- "filesRemaining" Number of files remaining to install or remove
- "bytesRemaining" Number of bytes of data remaining to install or remove
- "doingRemove" Non-zero if doing remove operation
-
- Returns:
- "passwordPtr" Pointer to password string
- "result" Hook result code (siHookNoErr, siHookQuit, siHookAbort)
-
- This function is called when the install button or the remove button is
- clicked to begin installing or removing files.
- ******************************************************************************/
- {
- Str255 promptStr;
- Point sfWhere = { -1, -1 };
- SFReply sfReply;
-
- if (gParms->doingRemove)
- return; // Skip for remove operations
-
- // Display dialog prompting user to select the location to install the specified item
- GetIndString(promptStr, genIStrID, installPromptIStr); // Get install prompt
- if (promptStr[0] == 0)
- goto FatalError;
- GetIndString(gItemName, genIStrID, itemNameIStr); // Get item name
- if (gItemName[0] == 0)
- goto FatalError;
-
- if (gParms->groupEnvironFlags & siHookEnvSystem6OrLower)
- { // System 6 does not support auto-centering of dialog - set dialog location
- sfWhere.h = 56;
- sfWhere.v = 65;
- }
-
- LMSetSFSaveDisk(-gParms->targetVRefNum); // Set default directory to root
- LMSetCurDirStore(fsRtDirID);
-
- SFPPutFile(sfWhere, promptStr, gItemName, NULL, &sfReply, selectDlg, NULL);
- if (!sfReply.good)
- goto Abort; // User cancelled
-
- if (LMGetSFSaveDisk() != -gParms->targetVRefNum)
- { // Error - user specified a location off the target volume
- CautionAlert(changeVolAlrt, NULL);
- goto Abort;
- }
-
- gInstallDirID = LMGetCurDirStore(); // Save install directory ID
- BlockMove(sfReply.fName, gInstallName, sfReply.fName[0] + 1); // Save install name
-
- HDelete(gParms->targetVRefNum, gInstallDirID, gInstallName); // Delete possible duplicate file
- return; // Good completion
-
- // Abort operation
- Abort:
- gParms->result = siHookAbort;
- return;
-
- // Fatal error occurred
- FatalError:
- SysBeep(1);
- gParms->result = siHookQuit; // Force installer to quit
- }
-
-
- /*****************************************************************************/
- void BeforeItemFunction(void)
- /******************************************************************************
- Input parameters:
- "targetVRefNum" Volume reference number of target volume
- "groupAPFlags" Groups currently selected
- "groupQUSel"
- "groupVZSel"
- "group32Flags"
- "group64Flags"
- "group96Flags"
- "groupEnvironFlags"
- "filesRemaining" Number of files remaining to install or remove
- "bytesRemaining" Number of bytes of data remaining to install or remove
- "doingRemove" Non-zero if doing remove operation
- "anyItemsSkipped" Non-zero if any item has been skipped during operation
- "desVRefNum" Volume reference number of destination volume
- "desDirID" Directory ID of destination directory
- "itemName" Name of item to install or remove
- "itemIsFolder" Non-zero if item is a folder
- "fileType" File type (files only)
- "fileCreator" File creator (files only)
- "createDate" Creation date (files only)
- "lastModDate" Last modification date (files only)
- "rsrcForkLen" Length of resource fork (files only)
- "dataForkLen" Length of data fork (files only)
-
- Returns:
- "result" Hook result code (siHookNoErr, siHookQuit, siHookAbort, siHookSkip, siHookItemDone)
- "desDirID" Directory ID of destination directory
- "itemName" Name of item to install or remove
- "itemInfo" Reference passed to AfterItem call
-
- This function is called before each item is installed or removed.
- ******************************************************************************/
- {
- if (gParms->doingRemove)
- return; // Skip for remove operations
-
- // Check to see if this item is the one to relocate
- if (!EqualString(gParms->itemName, gItemName, true, true))
- return; // Names do not match - no action required
-
- // Names match - change the destination directory and the item name
- gParms->desDirID = gInstallDirID;
- BlockMove(gInstallName, gParms->itemName, gInstallName[0] + 1);
- }
-